Project Code Quality Assurance with Duster and Simple-Git-Hooks
Introduction
In our continuous effort to maintain high code quality standards and ensure consistent coding practices across our team, we've implemented an automated linting and fixing mechanism using duster in conjunction with simple-git-hooks. This approach helps us automatically identify and fix common coding issues before they're committed to our repository, saving time during code reviews and maintaining our codebase's overall health.
Why Duster with Simple-Git-Hooks?
- Automated Code Quality Checks: Automatically ensures that our code adheres to defined coding standards and styles, reducing the need for manual code reviews for style violations.
- Efficiency: Saves time and effort by catching and fixing issues early in the development process.
- Consistency: Enforces coding standards across the team, leading to a more uniform codebase that's easier to read, maintain, and debug.
Setting Up Your Local Environment
To take advantage of this automated code quality assurance process, you'll need to set up duster and simple-git-hooks in your local development environment. Here's how:
Step 1: Dependencies
Run composer install and yarn install to get both duster and simple-git-hooks
Step 2: Set up hooks
Run yarn run dev.
Internally, it will run npx simple-git-hooks to set up the configured simple-git-hooks commands in package.json.
That's all, your hook is ready, and it will automatically run before each commit. Duster will fix only modified files, and those fixes will be added to that commit
Step 3: Set up PhpStorm
To avoid waiting until commit time for those fixes, you should set up PhPStorm to run the same commands on save. The hook should only be a safety measure.
-
Create a Duster file watcher

-
Enable it in "Actions on save"

-
Make sure PHP is disabled from "Reformat code"
-

If, for any reason, you need to disable the hooks, you can do it using rm -f .git/hooks/*. Use npx simple-git-hooks or just yarn run dev to set them again later.
Larastan (PHPStan)
The ./vendor/bin/phpstan analyse command will be executed along with duster's fix.
If there's any error found, you may fix it using ./vendor/bin/phpstan analyse --fix.
An initial baseline might be set for some projects to avoid reformating the whole codebase (./vendor/bin/phpstan analyse --generate-baseline). It would be stored at phpstan-baseline.neon.
Larastan is not configured as an "on save" action because it's quite resource-intensive and might take a while to run.
PhpStorm editorconfig
-
We use EditorConfig and the PhpStorm official plugin to format non-PHP code. The way we implement it is quite practical and comfortable.
-
What we need to do is enable the use of this plugin in the PhpStorm config. You may have to install the plugin yourself or it may already be disabled.

- We have only 1 .editorconfig file, we centralize everything in zoo, make sure you have in your project an .editorconfig file in your root directory with a symlink to that file. All other projects have a, assuming the dir structure is always the same:

-
From now on, any format change is done directly in Zoo.
-
You must check “reformat code” (except for php, we use Duster for that) and “Optimize import” to do the formatting when we save the file.
